<?php
/* @var $this ProductController */
/* @var $model Product */
/* @var $form CActiveForm */
?>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'product-form',
	'enableAjaxValidation'=>false,
  'htmlOptions'=>array('enctype' => 'multipart/form-data')
)); ?>

  <p class="note">
    Fields with <span class="required">*</span> are required.
  </p>

  <?php echo $form->errorSummary($model); ?>

  <div class="row">
  <?php echo $form->labelEx($model,'categoryID'); ?>
  <?php echo $form->dropdownList($model,'categoryID', Category::model()->getAllChildren(), array('prompt' => Yii::t('default', 'Chọn loại sản phẩm')))?>
  </div>


  <div class="row">
  <?php echo $form->labelEx($model,'name'); ?>
  <?php echo $form->textField($model,'name',array('size'=>60,'maxlength'=>255)); ?>
  </div>

 


  <div class="row">
    <?php echo $form->labelEx($model,'description'); ?>
  
    <?php
    $this->widget('ext.ckeditor.CKEditorWidget',array(
            "model"=>$model,
            "attribute"=>'description',
            "config" => array(
              "height"=>"300px",
    ),
    ));
    ?>
  </div>

  <div class="row">
  <?php echo $form->labelEx($model,'sort'); ?>
  <?php echo $form->textField($model,'sort'); ?>
  </div>

  <div class="row">
     <?php echo $form->labelEx($model,'enabled'); ?>
     <?php echo $form->radioButtonList($model, 'enabled', array('1' => Yii::t('default', 'Có'), '0' => Yii::t('default', 'Không')), array('separator'=>'', 'template'=>' {input} {label} ')); ?>
  </div>

  <div class="row">
  <?php echo $form->labelEx($model, Yii::t('default', 'Images')); ?>
  <?php
  $this->widget('CMultiFileUpload', array(
    'model'=>$model,
    'name' => 'Product[image]',
    'accept'=>'jpeg|jpg|gif|png',
    'denied'=>yii::t('default', 'Accept files').': jpg, jpeg, gif, png.',
    'max'=>-1,
    'duplicate'=>Yii::t('default', 'Duplicated file!'),
    'remove'=>'[x] ',
    'options'=>array( 
  )
  ));
  ?>

  <?php if(!$model->isNewRecord && !empty($image)) {?>
    <div class="clearfix">
    <?php foreach ($image as $item) { ?>
      <div class="MultiFile-label" id="file_<?php echo $item['id']?>">
        <a href="javascript: void(0)"
          onclick="DeleteImage('<?php echo $item['id']?>')"><i
          class="icon-remove"></i> </a>
          <?php echo CHtml::link($item['name'], Yii::app()->baseUrl . '/upload/product/' . $item['save'], array('target' => '_blank')); ?>
      </div>
      <?php } ?>
    </div>
    <?php }?>
    <p class="note">
    <?php echo yii::t('default', 'Accept files')?>
      : jpg, jpeg, gif, png.
    </p>
  </div>


  <div class="row buttons">
  <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
  </div>

  <?php $this->endWidget(); ?>

</div>
<!-- form -->
<script type="text/javascript">
function DeleteImage(id) {
  var notice = 'Bạn có chắc chắn là muốn xóa hình ảnh này không?';
  if(confirm(notice)) {
    $.ajax({
        type: "GET",
        url: baseUrl + '/admin/product/deleteimage',
        data: {id: id},
        success: function(result){
          if (result == 'success') {
            $("#file_"+id).remove();
          }
       }
      });
  }
}
</script>
